<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator"
	prefix="decorator"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set value="<%=request.getContextPath()%>" var="ctx"></c:set>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="renderer" content="webkit">
<link href="${ctx}/decorators/css/bootstrap.min.css?v=3.4.0" rel="stylesheet">
<link href="${ctx}/decorators/font-awesome/css/font-awesome.css?v=4.3.0" rel="stylesheet">
<link href="${ctx}/decorators/css/animate.css" rel="stylesheet">
<link href="${ctx}/decorators/css/style.css?v=2.2.0" rel="stylesheet">
<link href="${ctx}/decorators/css/plugins/dataTables/dataTables.bootstrap.css"	rel="stylesheet">
<link href="${ctx}/decorators/css/plugins/dataTables/tableTools.css"  rel="stylesheet">
<!-- Mainly scripts -->
<script src="${ctx}/decorators/js/jquery-2.1.1.min.js"></script>
<script src="${ctx}/decorators/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="${ctx}/decorators/js/bootstrap.min.js?v=3.4.0"></script>
<script	src="${ctx}/decorators/js/plugins/dataTables/jquery.dataTables.js"></script>
<script	src="${ctx}/decorators/js/plugins/dataTables/dataTables.bootstrap.js"></script>
<script	src="${ctx}/decorators/js/plugins/dataTables/dataTables.tableTools.min.js"></script>
<script src="${ctx}/decorators/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script type="text/javascript" src="${ctx}/assert/js/jquery.validate.min.js"></script>
<script type="text/javascript" src="${ctx}/assert/js/md5.js"></script>
<!-- Custom and plugin javascript -->
<script src="${ctx}/decorators/js/hplus.js?v=2.2.0"></script>
<script src="${ctx}/decorators/js/plugins/pace/pace.min.js"></script>
<title><decorator:title default="SmartFCRM" /></title>
<decorator:head />
<body>
	<div id="wrapper">
		<nav class="navbar-default navbar-static-side" role="navigation">
		<div class="sidebar-collapse">
			<ul class="nav" id="side-menu">
				<li class="nav-header">
					<div class="dropdown profile-element text-center">
						<span> 
							<img class="img-circle"src="${ctx}/assert/images/logo.png" style="width: 60px; height: 60px; ">
						</span> 
							<span class="block m-t-xs"> <strong class="font-bold text-info">千里码数据服务有限公司</strong></span>
						</a>
					</div>
					<div class="logo-element">千里码</div>
				</li>
				<li><a href="${ctx}/admin/index"><i class="fa fa-th-large"></i>
						<span class="nav-label">主页</span> </a></li>
					
				<li><a href="${ctx}/admin/vendorList"><i class="fa fa-th-list"></i>
					<span class="nav-label">商家/产品管理</span> </a></li>	
				<li><a href="${ctx}/admin/templateList"><i class="fa fa-edit"></i>
					<span class="nav-label">模版管理</span> </a></li>
				<li><a href="index.html#"><i class="fa fa-bar-chart"></i>
						<span class="nav-label">数据统计</span> <span class="fa arrow"></span></a>
					<ul class="nav nav-second-level">
						<!-- <li><a href="${ctx}/admin/hbStatistic">红包统计</a></li> -->
						<!-- <li><a href="${ctx}/admin/qrcodeStatistic">二维码扫码统计</a></li> -->
						<li><a href="${ctx}/admin/godStatistic">产品数据统计</a></li>
					</ul></li>
					
				<li><a href="${ctx}/admin/adminList"><i class="fa fa-user"></i>
						<span class="nav-label">后台用户管理</span> </a></li>
						
				<li><a href="${ctx}/admin/QRCode"><i class="fa fa-qrcode"></i>
					<span class="nav-label">二维码生成</span> </a></li>
			</ul>

		</div>
		</nav>

		<div id="page-wrapper" class="gray-bg dashbard-1">
			<div class="row border-bottom">
				<nav class="navbar navbar-static-top" role="navigation"
					style="margin-bottom: 0">
				<div class="navbar-header">
					<a class="navbar-minimalize minimalize-styl-2 btn btn-primary "
						href="#"><i class="fa fa-bars"></i> </a>
				</div>
				<ul class="nav navbar-top-links navbar-right">
					<li class="dropdown">
						<span > 
							   <a href="${ctx}/admin/index" title="返回首页" >
									<i class="fa fa-home"></i>
								</a>
						<span class="m-r-sm text-muted welcome-message">
								欢迎您
								<a data-toggle="dropdown" class="dropdown-toggle" href="#" aria-expanded="true" style=" background-color:#F3F3F4;"> 
									<span class="divider">${admin.username }
								 		<b class="caret"></b>
									</span>
							 	</a>
								<ul class="dropdown-menu animated fadeInRight m-t-xs">
									<li><a href="#" data-toggle="modal"  
										data-target="#alterModal" onclick="showModel();">修改密码</a></li>
								</ul>
								</span>
						</span>
					</li>

					<li><a href="${ctx}/admin/logout"> <i
							class="fa fa-sign-out"></i> 退出
					</a></li>
				</ul>

				</nav>
			</div>
			<!-- 修改密码的模态层 -->
			<div class="modal fade" id="alterModal" tabindex="-1" role="dialog"
				aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal"
								aria-label="Close">
								<span aria-hidden="true">&times;</span>
							</button>
							<h4 class="modal-title" id="myModalLabel">修改密码</h4>
						</div>
						<div class="modal-body">
							<form class="form-horizontal" action="${ctx}/admin/savePwd"
								name="pwdFrom" id="pwdFrom" method="post">
								<input type="hidden" value="${admin.id }" id="id" name="id" />
								<div class="form-group">
									<label class="col-lg-3 control-label">用户名称：</label>
									<div class="col-lg-8">
										<input type="text" class="form-control" name="username"
											disabled="disabled" id="signscore"
											value="${admin.username }">
									</div>
								</div>
								<div class="form-group">
									<label class="col-lg-3 control-label">原密码：</label>
									<div class="col-lg-8">
										<input type="password" class="form-control" name="oldPwd"
											id="oldPwd" value="" />
										<input type="hidden" name="oldPassword" id="oldPassword" value="" />	
									</div>
								</div>
								<div class="form-group">
									<label class="col-lg-3 control-label">新密码：</label>
									<div class="col-lg-8">
										<input type="password" class="form-control" name="pwdMd5"
											id="pwdMd5" value="" />
										<input type="hidden" name="pwd"  id="pwd" value="" />
									</div>
								</div>

								<div class="form-group">
									<div style="display: none" id="msgDiv">
										<label id="errMsg" style="color: red"></label>
									</div>
									<div class="col-lg-offset-9 col-lg-8">
										<button class="btn btn-large btn-primary" id="saveBtn"
											name="saveBtn" onclick="checkPwd();return false;">保存</button>
									</div>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>

			<!--被装饰区域 start--->
			<decorator:body />
			<!--被装饰区域 end--->

			<div class="footer">
				<div class="pull-right">
					By：<a href="http://www.qlm.im" target="_blank">千里码数据服务有限公司</a>
				</div>
				<div>
					<strong>Copyright</strong> qlm &copy; 2015
				</div>
			</div>

		</div>
	</div>
</body>
<script type="text/javascript">
	function checkForm() {
		$("#errMsg").html("");
		return $("#pwdFrom").validate({
			debug : false,
			rules : {
				oldPwd : {
					required : true,
					minlength : 6,
					maxlength : 16
				},
				pwdMd5 : {
					required : true,
					minlength : 6,
					maxlength : 16
				}
			},
			messages : {
				oldPwd : {
					required : "请输入原密码",
					minlength : "原密码不能小于6位",
					maxlength : "原密码最多为16位"

				},
				pwdMd5 : {
					required : "请输入新密码",
					minlength : "新密码不能小于6位",
					maxlength : "新密码最多为16位"
				}
			}
		});
	};

	function showModel() {
		//初始值设定
		$("#oldPwd").val("");
		$("#pwdMd5").val("");
		$("#errMsg").html("");
		$(".error").html("");
		$('input[type="password"]').attr("class", "form-control");
	};

	function checkPwd() {
		$("#errMsg").html("");
		var oldPwd = $("#oldPwd").val();
		var pwdMd5 = $("#pwdMd5").val();
		var oldPasswordMd5 = hex_md5($("#oldPwd").val());
		var pwd = hex_md5($("#pwdMd5").val());
		$("#oldPassword").val(oldPasswordMd5);//密码加密后传输
		$("#pwd").val(pwd); //密码加密后传输
		//表单验证
		if (!checkForm().form()) {
			return;
		} else if (oldPwd == pwdMd5) {
			$("#msgDiv").show();
			$("#errMsg").html("新密码和原密码一致，请重新输入！");
			$("#errMsg").show();
			return;
		} else {
			$.ajax({
				type : "POST",
				url : "${ctx}/admin/checkPwd", //换成你要请求的action, paperId 是url参数
				data : {
					oldPassword : oldPasswordMd5
				},
				async : false,
				error : function(msg) {
					$("#msgDiv").show();
					$("#errMsg").html("原密码输入错误！");
					$("#errMsg").show();
				},
				success : function(data) {
					if (data == "success") {
						savePwd();
					} else {
						$("#msgDiv").show();
						$("#errMsg").html("原密码输入错误！");
						$("#errMsg").show();
					}
				}
			});
		}
	}

	function savePwd() {
		$.ajax({
			type : "POST",
			url : "${ctx}/admin/savePwd", //换成你要请求的action, paperId 是url参数
			data : $("#pwdFrom").serialize(),
			async : false,
			error : function(msg) {
				document.getElementById("errMsg").innerHTML = "修改失败！";
			},
			success : function(data) {
				if (data == "success") {
					document.getElementById("errMsg").innerHTML = "修改成功！";
					document.location.reload();
				}
			}
		});
	}
</script>
</html>